/*
   Copyright (c) 2020 Shanghai Xuanzi Technology Co. Ltd https://xuanzi.ltd
   XZUnitTest is licensed under the Mulan PSL v1.
   You can use this software according to the terms and conditions of the Mulan PSL v1.
   You may obtain a copy of Mulan PSL v1 at:
      http://license.coscl.org.cn/MulanPSL
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
   PURPOSE.
   See the Mulan PSL v1 for more details. 
 */

package xuanzi.h5.unittest;

public abstract class StepTest implements Asserts.Countable{

	String name;
	
	public StepTest(String name) {
		Asserts.log("%c 🕷 "+name,"color:blue;font-size:15px;border-left:2px solid blue");
		this.name = name;
		startTime = System.currentTimeMillis();
		Asserts.countables.add(this);
		doStep();
	}
	
	long startTime;
	int pass;
	int error;
	
	protected abstract void doStep();
	
	public void finish() {
		Asserts.countables.remove(this);
		long time = System.currentTimeMillis() - startTime;
		String color = (error>0?"red":"green");
		String result = error>0?(" Has "+error+" Errors"):" is Pass";
		Console.log(" %c "+name+" "+(pass+error)+" Tests "+result+". ","color:"+color+";font-size:14px;border-left:16px solid "+color);
		Console.log(" %c Test Pass : "+(pass)+"  ⏱ "+time+"ms","margin-left:26px;color:green;border-left:8px solid green");
		if(error>0) {
			UnitTest.changeTitle("Warning :"+name+" Tests Has Errors ,Please See Console."); 
			Console.log(" %c Test Error : "+(error)+" 🕷 ","margin-left:26px;color:red;border-left:8px solid red");
		}
	} 
	
	@Override
	public void error(String message) { 
		error++;
	}
	
	@Override
	public void pass(String message) { 
		pass++;
	}
	
}
